<template>
 <div class="pageContent">
   <input class="userID" v-model="userID"/>
   <button @click="handleLogin">登录当前用户</button>
    <button class="methods" @click="testNavi">
     发起会话
    </button>
  </div>
</template>

<script>
import { mapState, mapGetters } from 'vuex'
import { genTestUserSig } from '../../../static/utils/GenerateTestUserSig'
export default {
  data () {
    return {
      scrollTop: 0,
      userID:'user0',
    }
  },
  computed: {
    ...mapState({
      currentPage: state => state.global.currentPage,
      // isSdkReady: state => state.global.isSdkReady,
    }),
      ...mapGetters(['myInfo'])
    },
  onPageScroll (event) {
    this.scrollTop = event.scrollTop
  },
  methods: {
    testNavi() {
      console.warn('testNavi')
      wx.navigateTo({url:'/pages/search/main?type=user'})
    },
    // 点击登录进行初始化
    handleLogin() {
      const userID = this.userID
      // case1: 要登录的用户是当前已登录的用户，则直接跳转即可
      console.warn('this.myInfo',this.myInfo)
      if (this.myInfo.userID && userID === this.myInfo.userID) {
        return
      }
      // case3: 正常登录流程
      this.login(userID)
    },
    login (userID) {
      let userSig = genTestUserSig(userID).userSig
      wx.$app.login({
        userID,
        userSig: userSig
      }).then((res) => {
        console.warn('contact=login',res)
        this.$store.commit('setRtcConfig', {userID: userID, userSig: userSig, sdkAppID: wx.$sdkAppID})
        // wx.switchTab({ url: '../index/main' }) //可以直接切换到视频通话主页
      }).catch(() => {
      })
    },
  },
  created () {
    console.warn('--------contact=created进入main首页会触发contact的created方法------')
    console.warn('--------不要在此次调登录，sdk还没有准备好，------')
  },
  onLoad(){
    // this.handleLogin()
  },
  onShow () {
  },
}
</script>

<style lang='stylus'>
.pageContent{

}
.userID{
  height 100rpx
  padding 20rpx
  border 1rpx solid #666666
}

</style>
